package com.platform.core.web.controller;

import com.platform.comm.web.results.DataJsonResult;
import com.platform.comm.web.results.JsonResult;
import com.platform.comm.web.results.PageListJsonResult;
import com.platform.core.service.CdComManageBiz;
import com.platform.dto.CdComManageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description: -客户(公司)管理接口
 *
 * @author Coder
 */
@RestController
@RequestMapping(name = "管理", path = "/management/cdComManage")
public class CdComManageController extends BaseController{

    private final CdComManageBiz cdComManageBiz;

    @Autowired
    public CdComManageController(CdComManageBiz cdComManageBiz) {
        this.cdComManageBiz = cdComManageBiz;
    }

    /**
     * 分页查询数据
     */
    @PostMapping(name = "查询列表", path = "/search")
    public PageListJsonResult<CdComManageDto> search(@RequestBody Map<String,String> params) {
        Page<CdComManageDto> entities = cdComManageBiz.search(params, getPageable(params));
        return new PageListJsonResult<>(entities);
    }

    /**
     * 分页查询数据
     */
    @PostMapping(name = "查询列表", path = "/searchList")
    public DataJsonResult<List<CdComManageDto>> searchList() {
        return DataJsonResult.succeed(cdComManageBiz.searchList());
    }

    /**
    * 查询明细数据
    */
    @PostMapping(name = "查询明细", path = "/detail")
    public DataJsonResult<CdComManageDto> detail(@RequestParam String id) {
        return DataJsonResult.succeed(cdComManageBiz.detail(id));
    }

    /**
    * 新增
    */
    @PostMapping(name = "新增", path = "/create")
    public JsonResult create(@RequestBody CdComManageDto req) {
        cdComManageBiz.add(req);
        return JsonResult.success();
    }

    /**
    * 修改数据
    */
    @PostMapping(name = "修改", path = "/modify")
    public JsonResult modifyCdComManage(@RequestBody CdComManageDto req) {
        cdComManageBiz.modify(req);
        return JsonResult.success();
    }

    /**
    * 删除
    */
    @PostMapping(name = "删除", path = "/remove")
    public JsonResult remove(@RequestBody Map<String,String> params) {
        String id = params.get("id");
        cdComManageBiz.remove(id);
        return JsonResult.success();
    }
}
